package com.walle.userservice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangjiapeng
 * @Package com.walle.userservice
 * @Description: ${todo}
 * @date 2019/2/13 11:24
 */
public class Floor {

    private static Map<Integer,Long> cache;

    public static void main(String[] args) {
        int floor = 5;
        cache = new HashMap(floor);
        cache.put(1,1L);
        cache.put(2,2L);
        long start = System.currentTimeMillis();
        System.out.println(calculate(floor));
        System.out.println("耗时:"+(System.currentTimeMillis() -start));
    }

    public static long calculate(int floor){
        if (floor <= 0){
            return  0;
        }else if(cache.get(floor) != null){
            return cache.get(floor);
        }
        long result = calculate(floor-1) + calculate(floor - 2);
        cache.put(floor,result);
        return result;
    }
}
